﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Windows;
using WinFormSample;
using System.Windows.Threading;
using Osteox.ManagedCv;
using System.Reflection;
using System.IO;

namespace WpfSample
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        const string FILENAME = "Filters.settings"; 

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), FILENAME);
            CvException.TurnRaiseException(true);
            SampleProperty property = SampleProperty.Current;
            try
            {
                property.Load(path);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        protected override void OnExit(ExitEventArgs e)
        {
            string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), FILENAME);
            SampleProperty property = SampleProperty.Current;
            property.Save(path);

            base.OnExit(e);
        }

        private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            MessageBox.Show(e.Exception.ToString());
            e.Handled = true;
        }
    }
}
